<template>
  <div>

    <q-layout>
      <q-layout-header ref="header">
        <xheader :title="title"></xheader>
      </q-layout-header>
      <q-page-container>

        <q-page padding>

          <q-input ref="code" float-label="随工单号" v-model="code" clearable
                   @blur="searchBatchInfo"
                   @keydown.enter="searchBatchInfo" :after="$parent.getScanIcon('code',this)"/>
          <q-input float-label="随工单信息" placeholder="请输入随工单号" readonly v-model="codeInfo" type="textarea" rows="3"
                   hide-underline/>
          <q-input float-label="硅锭/棒信息" placeholder="请输入随工单号" readonly v-model="batchInfo" type="textarea" rows="2"
                   hide-underline/>
          <q-btn label="提交" color="primary" class="full-width" @click="submit"/>
        </q-page>

      </q-page-container>
    </q-layout>
  </div>
</template>

<script>

import utils from '../../js/utils'
import Xheader from '../../components/xheader'

export default {
  name: 'use_main_product',
  components: { Xheader },
  props: {
    title: {}
  },
  data: () => ({
    code: '',
    codeInfo: '',
    batchNo: '',
    batchInfo: '',
    batchId: '',
    ggBatchNo: ''

  }),
  methods: {
    submit () {
      if (!this.ggBatchNo) {
        this.$parent.info('主材批次不能为空！')
        return
      }
      this.axios.post(this.$conf.server + '/useMaterial/subMainProductGet', this.$qs.stringify({
        id: this.batchId, batchNo: this.ggBatchNo
      })).then(res => {
        this.$parent.info(res.data.msg)
        if (res.data.result) {
          this.ggBatchNo = ''
          this.batchId = ''
          this.code = ''
          this.batchNo = ''
          this.codeInfo = ''
          this.batchInfo = ''
        }
      })
    },
    popupFilter () {

    },
    searchBatchInfo () {
      if (this.code !== '') {
        this.axios.post(this.$conf.server + '/manuBatch/searchBatchInfo', this.$qs.stringify({
          code: this.code
        })).then(res => {
          if (res.data.result) {
            this.batchId = res.data.ID
            this.batchNo = this.code
            this.codeInfo = '规格：' + utils.nvl(res.data.CUT_METHOD) +
                (res.data.TYPE ? '\r\n类型：' + res.TYPE : '') +
                (res.data.IS_TEST === 'Y' ? '\r\n<span style=\'color: #f00;\'>试验件</span>' : '') +
                '\r\n' + utils.nvl(res.data.DESCRIPTION)

            this.getMaterialInfo()
          } else {
            this.$parent.info(res.data.msg)
          }
        })
      }
    },
    getMaterialInfo () {
      if (this.batchNo !== '') {
        this.axios.post(this.$conf.server + '/useMaterial/getMaterialInfo',
          this.$qs.stringify({ batchNo: this.batchNo })).then(res => {
          if (res.data.result) {
            this.ggBatchNo = this.batchNo
            this.batchInfo = utils.nvl(res.data.PCODE) + '，' + utils.nvl(res.data.PNAME) +
                '\r\n' + utils.nvl(res.data.DESCRIPTION)
          } else {
            this.$parent.info(res.data.msg)
          }
        })
      }
    }
  },
  created () {

  }
}
</script>

<style scoped>

</style>
